import { createApp, type App as VueApp } from 'vue'
import router from './router'
import { store } from './store'
import '@/styles/index.less'
// import StarportPlugin from 'vue-starport' // 具有动画的跨路由共享组件
import App from './App.vue'
import { setupStore } from '@/store'
import globalComponents from '@/components'
import { setupGlobDirectives } from '@/directives'
import chartResize, { useChartResize } from './plugins/chartResize'

import { initGetJsonContextTool, showImportJsonContextSymbol } from '@/utils'

import 'virtual:svg-icons-register'

const app: VueApp<Element> = createApp(App)

setupStore(app)
setupGlobDirectives(app)
app.use(router)
app.use(store)
app.use(chartResize)
app.use(globalComponents)
app.use(initGetJsonContextTool, { path: '/public/json/' })
// app.use(StarportPlugin())
app.mount('#app')

window.addEventListener('DOMContentLoaded', () => {
  window.addEventListener('reset', () => {
    const chartState = useChartResize()

    if (!chartState.list.length) {
      return
    }
    chartState.list.forEach((chart) => {
      chart.resize()
    })
  })
})
